﻿<app:SpottedPageBase
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:app="clr-namespace:Spotted.Core" x:Class="Spotted.Views.MainPage"
    xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="66*" />
            <RowDefinition Height="414*" />
        </Grid.RowDefinitions>

        <toolkit:PhoneTextBox Hint="filter places" Grid.Row="0" x:Name="filterText"
                              Background="{StaticResource SpottedLightGrayBackgroundBrush}"
                              Foreground="{StaticResource SpottedGrayColorBrush}"
                              BorderBrush="{StaticResource SpottedGrayColorBrush}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="KeyUp">
                    <cal:ActionMessage MethodName="FilterPlaces">
                        <cal:Parameter Value="{Binding ElementName=filterText, Path=Text}" />
                    </cal:ActionMessage>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </toolkit:PhoneTextBox>

        <ListBox ItemsSource="{Binding PlacesListing}" Grid.Row="1" Name="PlacesListBox">
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="HorizontalAlignment" Value="Stretch" />
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="{StaticResource SpottedGrayColorBrush}" BorderThickness="0,0,0,1" Padding="4">
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="{Binding Name}" Style="{StaticResource PlacesListboxText}" />
                            <TextBlock Text="{Binding RatingText, StringFormat='Rating: {0}'}" Style="{StaticResource SmallText}" />
                        </StackPanel>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <cal:ActionMessage MethodName="PlaceSelected">
                        <cal:Parameter Value="{Binding ElementName=PlacesListBox, Path=SelectedItem}" />
                    </cal:ActionMessage>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </ListBox>
    </Grid>

    <!-- The application bar -->
	<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True">
            <shell:ApplicationBar.Buttons>
                <cal:AppBarButton IconUri="/Assets/Icons/appbar.add.rest.png"
                                  Text="add spot"
                                  Message="AddLocation" />
                <cal:AppBarButton IconUri="/Assets/Icons/appbar.map.png"
                                  Text="see map"
                                  Message="ShowMap" />
                <cal:AppBarButton IconUri="/Assets/Icons/appbar.refresh.png"
                                  Text="refresh"
                                  Message="RefreshLocation" />
            </shell:ApplicationBar.Buttons>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
</app:SpottedPageBase>